<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="Content-Script-Type" content="text/javascript" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<meta http-equiv="keywords" content="" />
		<meta http-equiv="description" content="" />
		<title>見積管理</title>

		<link rel="stylesheet" href="./assets/styles/default.css" type="text/css" />
		<script src="assets/scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
		<script src="assets/scripts/menu.js" type="text/javascript"></script>
		<script src="assets/scripts/table.js" type="text/javascript"></script>

		<script src="assets/scripts/ui/jquery-ui-1.7.2.custom.js" type="text/javascript"></script>
		<link type="text/css" href="./assets/styles/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
		<script type="text/javascript" src="./assets/scripts/ui/ui.core.js"></script>
		<script type="text/javascript">
		$(function() {
			// メッセージのフェード
			$('.message').fadeIn("slow");

		});
		
		function goBack(shop_id,shop_name,refer_price,cost_price,s_unit,style){
			if(!window.opener.validationRepeat(shop_id,{{php}}echo $_GET['id']{{/php}})){
				alert("重複商品を挿入することはできません");
				return ;
			}
			window.opener.document.getElementById("style_{{php}}echo $_GET['id']{{/php}}").value=style;
			window.opener.document.getElementById("shop_id_{{php}}echo $_GET['id']{{/php}}").value=shop_id;
			window.opener.document.getElementById("shop_name_{{php}}echo $_GET['id']{{/php}}").value=shop_name;
			window.opener.document.getElementById("shop_name_span_{{php}}echo $_GET['id']{{/php}}").innerHTML=shop_name;
			window.opener.document.getElementById("refer_price_{{php}}echo $_GET['id']{{/php}}").value=parseInt(refer_price);
			window.opener.document.getElementById("s_unit_{{php}}echo $_GET['id']{{/php}}").value=s_unit;
			window.opener.document.getElementById("multiple_{{php}}echo $_GET['id']{{/php}}").value='';
			window.opener.document.getElementById("num_{{php}}echo $_GET['id']{{/php}}").value='';
			window.opener.document.getElementById("cost_price_{{php}}echo $_GET['id']{{/php}}").value=cost_price;
			window.opener.document.getElementById("money_{{php}}echo $_GET['id']{{/php}}").innerHTML=formatNumber(parseInt(refer_price)*1*1);
			var m = parseFloat(refer_price)*1.0*1;
			window.opener.document.getElementById("profit_{{php}}echo $_GET['id']{{/php}}").innerHTML=parseInt(((m-cost_price*1)/m)*100)+"%";
			window.opener.compute();
			window.close();
			
		}
		
		function formatNumber(str) { 
			str=str+"";
		    if(str.length <= 3){  
		        return str;  
		    } else {  
		        return formatNumber(str.substr(0,str.length-3))+','+str.substr(str.length-3);  
		    }  
		}  
		</script>
	
	</head>
	<body  >
	
		<div id="container"><div class="wrapper">

			<h3>商品マスタ選択</h3>
			
			<p class="message">条件を入力し、検索ボタンをクリックしてください。</p>
			
			<form action="shop_search.php" method="get">
			<input type="hidden" name="id" value="{{php}}echo $_GET['id']{{/php}}" />
			<table id="inquiry_result" class="formTable">
				<thead>
					<tr>
						<th>型番</th>
						<td><input type="text" name="type" class="text" value="{{$forms.type}}" /></td>
					</tr>
					<tr>
						<th>商品名</th>
						<td><input type="text" name="shop_name"  class="text" value="{{$forms.shop_name}}" /></td>
					</tr>
					<tr>
						<th>仕様</th>
						<td><input type="text" name="style" class="text" value="{{$forms.style}}" /></td>
					</tr>					
				</thead>			
			</table>
			<input type="hidden" name="flag" value="0" id="flag" />			
			<p class="button">
				<button type="submit" id="btn_search" class="submit"><span>検索</span></button>
			</p>
			</form>

			<p class="message">検索へ<span style="color: red">{{$cnt}}</span>レコード</p>

{{ if $cnt > 0 }}
			
			<h2>検索結果</h2>
			<table id="inquiry_result" class="formTable">
				<thead>
					<tr align="center">
						<th>型番</th>
						<th style='width:30%'>商品名</th>
						<th>仕様</th>
						<th>参考価格</th>
						<th>原価</th>
						<th>セット</th>
					</tr>

				</thead>
				<tbody>
					
{{ foreach from=$shoplist key=k item=v }}
					<tr>
						<td>{{ $v.type }}</td>
						<td>{{ $v.shop_name }}</td>
						<td>{{ $v.style }}</td>
						<td>￥{{ $v.refer_price }}</td>
						<td>￥{{ $v.cost_price }}</td>
						<td align="center"><a href="javascript:goBack({{ $v.shop_id }},'{{ $v.shop_name }}',{{ $v.refer_price }},{{ $v.cost_price }},'{{ $v.s_unit }}','{{ $v.style }}')">[セット]</a></td>
					</tr>
{{ /foreach }}				
				</tbody>
			</table>

			<p align="center">
{{ if $page.current > 1 }}
				<a href="shop_search.php?page={{ $page.current-1 }}{{ $page.query }}&id={{php}}echo $_GET['id']{{/php}}">前の{{ $page.item }}件</a>&nbsp;&nbsp;
{{ /if }}
{{ foreach from=$page.paging key=k item=v }}
{{ if $v < $page.current+15 }}
{{ if $page.current == $v }}
{{ $v }}&nbsp;
{{ else }}
				<a href="shop_search.php?page={{ $v }}{{ $page.query }}&id={{php}}echo $_GET['id']{{/php}}">{{ $v }}</a>&nbsp;
{{ /if }}
{{ /if }}
{{ /foreach }}
{{ if $page.end > $page.current }}
				<a href="shop_search.php?page={{ $page.current+1 }}{{ $page.query }}&id={{php}}echo $_GET['id']{{/php}}">次の{{ $page.item }}件</a>
{{ /if }}
			</p>	
			
{{ /if }}
		</div></div>
			
			
		<address>Copyright (C) SHIFT Inc. / All rights reserved</address>

	</body>
</html>